﻿Imports System.Xml

Public Class boxNew1
    Inherits System.Web.UI.UserControl

    Public objFunction As New FunctionClass
    Public objConfig As New Configs
    Public objAlert As New AlertClass

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim strHTML As New StringBuilder()
            Dim strHTML1 As New StringBuilder()
            Dim xml As String = ""
            Dim cnt As Integer = 0

            ' Box tin Noi Bat 
            xml = objFunction.ReadEndFile(Server.MapPath("/") & "static/outSite/listfiles/new5.xml")
            Dim rgx As New Regex("\n|\t|\r")
            xml = rgx.Replace(xml, "")
            Dim doc As New XmlDocument()
            doc.LoadXml(xml)
            Dim nodeList As XmlNodeList = doc.GetElementsByTagName("item")
            For Each n As XmlNode In nodeList
                Dim title As String = n.SelectSingleNode("title").InnerText
                Dim uri As String = n.SelectSingleNode("uri").InnerText
                strHTML.AppendLine("<li><a href=""/NewDetail.aspx?idNew=" & n.SelectSingleNode("id").InnerText & """ title=""" & title & """ target=""_blank"">" & title & "</a></li>")
                cnt = cnt + 1
            Next
            boxNewHot.InnerHtml = strHTML.ToString()
            strHTML = Nothing
            
            ' Box tin khuyen mai
            xml = objFunction.ReadEndFile(Server.MapPath("/") & "static/outSite/listfiles/new4.xml")
            xml = rgx.Replace(xml, "")
            doc.LoadXml(xml)
            nodeList = doc.GetElementsByTagName("item")
            For Each n As XmlNode In nodeList
                Dim title As String = n.SelectSingleNode("title").InnerText
                Dim uri As String = n.SelectSingleNode("uri").InnerText
                strHTML1.AppendLine("<li><a href=""NewDetail.aspx?idNew=" & n.SelectSingleNode("id").InnerText & """ title=""" & title & """ target=""_blank"">" & title & "</a></li>")
                cnt = cnt + 1
            Next
            boxNewPromo.InnerHtml = strHTML1.ToString()
            strHTML1 = Nothing
            doc = Nothing
            nodeList = Nothing
        Catch ex As Exception
            If objConfig.Developer.Equals("1") Then
                objAlert.ErrorBox(Page, "File: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.DeclaringType.Name & _
                                  " --- Function: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.Name & _
                                  " --- Mess: " & ex.Message.Replace("'", """"))
            Else
                objAlert.ErrorBox(Page, "Lỗi kỹ thuật, hãy thông báo lại với Admin, xin cảm ơn.")
            End If
        End Try
    End Sub

End Class